package com.dhcc.hikari.controller;

import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.dhcc.hikari.dto.Student;
import com.dhcc.hikari.entity.vo.Result;
import com.dhcc.hikari.entity.vo.ResultCode;
import com.dhcc.hikari.service.StudentService;
import com.dhcc.hikari.util.SnowFlakeWorker;
import com.google.common.collect.Lists;

import cn.hutool.core.util.RandomUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 学生前端控制器
 * 
 * @author 2019年6月25日09:27:05
 */
@Controller
@RequestMapping("/student")
@Api(tags = " 学生模块")
public class StudentController {

//	@Autowired
//	private StudentService studentService;
//	@Autowired
//	private SnowFlakeWorker snowFlakeWorker;
//
//	@ResponseBody
//	@RequestMapping(value = "/listStudent", method = RequestMethod.GET)
//	@ApiOperation(value="查询学生集合",nickname="用户模块")
//	public Result listStudent() {
//		return new Result(ResultCode.SUCCESS, studentService.selectByPrimaryKey(996018439061505L));
//	}
//
//	@ResponseBody
//	@RequestMapping(value = "/findById/{id}", method = RequestMethod.GET)
//	@ApiOperation(value="根据id查询",nickname="用户模块")
//	public Result findById(@PathVariable Long id) {
//		return new Result(ResultCode.SUCCESS,studentService.selectByPrimaryKey(id));
//	}
//
//	@ResponseBody
//	@RequestMapping(value = "/save", method = RequestMethod.POST)
//	@ApiOperation(value="保存",nickname="用户模块")
//	public Result save(@RequestBody Student student) {
//		return new Result(ResultCode.SUCCESS,studentService.insert(student));
//	}
//
//	@ResponseBody
//	@RequestMapping(value = "/update/{id}", method = RequestMethod.PUT)
//	@ApiOperation(value="更新",nickname="用户模块")
//	public Result update(@PathVariable Long id, @RequestBody Student student) {
//		Student currStudent = studentService.selectByPrimaryKey(id);
//		if (currStudent != null) {
//			currStudent.setName(student.getName());
//			currStudent.setAddress(student.getAddress());
//			currStudent.setAge(student.getAge());
//			currStudent.setEmail(student.getEmail());
//			studentService.updateByPrimaryKey(currStudent);
//			return new Result(ResultCode.SUCCESS,"更新成功");
//		} else {
//			return new Result(ResultCode.FAIL,"更新失败");
//		}
//	}
//
//	@ResponseBody
//	@RequestMapping(value = "/delete/{id}", method = RequestMethod.DELETE)
//	@ApiOperation(value="删除",nickname="用户模块")
//	public Result delete(@PathVariable Long id) {
//		studentService.deleteByPrimaryKey(id);
//		return new Result(ResultCode.SUCCESS,"删除成功");
//	}
//
//	@ResponseBody
//	@RequestMapping(value = "/batchInsert",method = RequestMethod.GET)
//	@ApiOperation(value="批量插入",nickname="学生模块")
//	public Result batchInsert() {
//		try {
//			List<String> list = Stream.of("kobe", "james", "steve", "wade", "anthnoy", "druant")
//					.collect(Collectors.toList());
//			List<Student> students = Lists.newArrayList();
//			for(int j=0;j<1000;j++) {
//				students = Lists.newArrayList();
//				for (int i = 0; i < 1000; i++) {
//					Student student = new Student();
//					student.setId(snowFlakeWorker.nextId());
//					student.setName(RandomUtil.randomEle(list));
//					student.setAge(18);
//					student.setAddress("广东省广州市");
//					student.setEmail("123456@qq.com");
//					students.add(student);
//				}
//				studentService.batchInsert(students);
//			}
//			return new Result(ResultCode.SUCCESS,"插入成功");
//		} catch (Exception e) {
//			e.printStackTrace();
//			return new Result(ResultCode.FAIL,"批量插入用户系统异常");
//		}
//	}

}
